package com.kfm.pm;

import java.util.HashMap;

public class HashMapDemo02 {

    public static void main(String[] args) {
        HashMap<Integer, TVPlay> hashMap = new HashMap<>();
        hashMap.put(1, new TVPlay("甄嬛传", 74));
        hashMap.put(2, new TVPlay("长风渡", 40));
        hashMap.put(3, new TVPlay("莲花楼", 40));
        hashMap.put(4, new TVPlay("长相思", 40));
        hashMap.put(5, null); // 键值都允许为null 但是只存在一个null键
        System.out.println(hashMap.containsKey(2)); // true
        System.out.println(hashMap.containsKey(5)); // false
        System.out.println(hashMap.get(2));
        System.out.println(hashMap.get(5)); // 不能通过get(key) == null 来判断是否有映射
        System.out.println(hashMap.containsValue(new TVPlay("长相思", 40))); // true
    }
}
